package com.bear.cmcc.NetTestHTTP.ui.adapter;

import com.bear.cmcc.NetTestHTTP.R;
import com.bear.cmcc.NetTestHTTP.component.InfoSubBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

/**
 * 管理频道适配器
 * 
 * @author jqa
 * 
 */
public class ChannelMgrAdapter extends BaseAdapter {
	private Context context;
	private List<InfoSubBean> mList;

	public ChannelMgrAdapter(Context context, List<InfoSubBean> list) {
		this.context = context;
		this.mList = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public InfoSubBean getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View view = LayoutInflater.from(context).inflate(R.layout.layout_channelmgr_item, null);
		RelativeLayout bgLayout = (RelativeLayout)view.findViewById(R.id.tv_bgLayout);
		TextView titleText = (TextView)view.findViewById(R.id.tv_Title);
		TextView contentText = (TextView)view.findViewById(R.id.tv_Message);
		ImageView flagImage = (ImageView)view.findViewById(R.id.tv_Sub);
		
		InfoSubBean b = getItem(position); 
		if(position%2==0){
			bgLayout.setBackgroundResource(R.color.setInfo_bg2);
		}else{
			bgLayout.setBackgroundResource(R.color.setInfo_bg1);
		}
		
		titleText.setText(b.getTitle());
		contentText.setText(b.getMessage());
		if(b.getFlag().equals("订阅")){
			flagImage.setImageResource(R.drawable.subscribe_checked_ico);
		}else{
			flagImage.setImageResource(R.drawable.subscribe);
		}
		
		return view;
	}


}
